Switching Example

FILE: Switch.cln

Introduction

The switch object, directs data under the control of the sheet. This makes it particularly useful when a section of calculation is repeated over and over, the switch object can make a decision without intervention from the user of the sheet. This sheet is set to demonstrate the use of the switch object on a simple model.

Scenario

As with the example Database.cln, we are calculating the end of year bonuses for employees. The rules for giving bonuses are different for management pay grades 1 and 2 to that of employee pay grades 3 to 8.

Managers get £1000 basic bonus, plus £1000 for every sales point they scored.

Employees get £100 for each year of their age.

In the following example sheet, we will use the switch object to direct the data to one of two calculator objects that calculate the bonus.

Click on each object, working along the pipes, top to bottom, to trace the flow of the calculation.


This is an Input Table. Here it is used to input the names, dates of birth, sales points over the year and pay group information for each employee.


This is an Announcer Object. It takes the array of information and chops it into rows, feeding the rows one-by-one through the next section of calculations. This allows us to use one group for calculating all of the bonus information.


This is a Reporter Object. It takes the result from the bonus calculations and reassembles them into a single result array.


This is a Switch Object. It has two states, when x[3]<3, Input A connects to Output A, in other words, when the pay grade is less than 3 (management) it connects to the managment pay calculation.

When the pay grade is 3 or more, it connects Input A to Output B. Output B sends the data through to the employee pay grade.

Notice that the control pipe X is connected to the same input data as the data we are feeding through. We are using the data itself in our test.

A typical snapshot of this data looks like this: {"Thimpson, K", \8th Nov 91, 98, 3}.

Notice that it's a 1 dimensional array, and that element 3 (elements are numbered 0,1,2,3) is the pay grade.


This is a Calculator Object. It is used here to calculate the management pay bonus.

This object contains the equation: {A[0],A[2]*1000+1000}

A[2]	Is element 2 of input A, which is the Sales Points built up over the year

A[2]*1000+1000	Is the bonus calculated from those Sales Points.

A[0]	Is the name of the manager

{ .... , ....}	Groups the results so into a single array with the name of the manager, followed by his or her bonus.


This is a Calculator Object. It is used to calculate the employee pay bonus.

This object contains the equation {A[0],(today-A[1])/365*100}

A[1]	Is the Date of birth

today-A[1]	Is the number of days old a person is

( ... )/365*100	Converts number of days to amount of bonus

A[0]	Is the name of the person

{... , ...}	Groups the name and bonus into an array


This is a Switch Object. Prior to this object, the two calculations have gone separate ways, this switch object recombines them into one pipe.

To do this it takes the same data pipe that was used as the control to the first switch object and performs the same two tests. This time however, the links are set to relink two inputs into 1.


This is an Output Table, it displays the results of the bonuses calculation.